package com.dd.seckill.cluster.config.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/9/8 14:29
 * @Description 类功能作用说明
 */
@Configuration
public class MQSecKillConfig {
    public static final String QUEUE = "seckillQueue";
    public static final String EXCHANGE = "seckillExchange";
    public static final String ROUTE = "seckill.message";

    @Bean // 配置队列 Bean
    public Queue queue_seckill() {
        return new Queue(QUEUE);
    }
    @Bean // 配置交换机 Bean
    public TopicExchange topicExchange_seckill() {
        return new TopicExchange(EXCHANGE);
    }
    @Bean // 配置队列绑定交换机 Bean 这里使用RabbitMQ的topic模式 相当于路由模式的模糊匹配
    public Binding binding_seckill() {
        return BindingBuilder
                .bind(queue_seckill())
                .to(topicExchange_seckill())
                .with(ROUTE);
    }
}
